from requests_html import HTMLSession
import pyperclip
# 获取请求对象
session = HTMLSession()
url = pyperclip.paste()
# 往网站发送get请求
page = session.get(url)
page.encoding = 'utf-8'
# （掘金酱https://e.juejin.cn/#/）远程主机强迫关闭了一个现有的连接。
# page.html.render()
# 打印整个页面代码文本
# print(page.text)
# 获取id为content-left的div标签，并且返回一个对象
content = page.html.find('p#imgList', first=True)
img_s = content.find('img')
for img in img_s:
    src = img.attrs['src']
    img_url = img.attrs['data-original'] if img.attrs.__contains__('data-original') else ''
    url = img_url if img_url != '' else src

    # print('url ', url)
    # _page = session.get(href)
    # _page.encoding = 'utf-8'
    # print(_page.html.find('h1#articleContentId', first=True).text)
    # c = _page.html.find('h1#articleContentId')
    # for x in c:
    #     print(x.attrs)